package com.mfangsoft.zhuangjialong.integration.fileupload.service.impl;

import java.util.Date;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mfangsoft.zhuangjialong.common.context.UserContext;
import com.mfangsoft.zhuangjialong.integration.fileupload.mapper.InterfaceManagementTemplateMapper;
import com.mfangsoft.zhuangjialong.integration.fileupload.model.InterfaceManagementTemplate;
import com.mfangsoft.zhuangjialong.integration.fileupload.service.FileUploadService;
@Service
public class FileUploadServiceImpl implements FileUploadService{
	
	@Autowired
	private InterfaceManagementTemplateMapper interfaceManagementTemplateMapper;

	@Override
	public Map<String,Object> selectIsFirstUpload() {
		Long user_id = UserContext.getCurrentUserId();
		Map<String,Object> map = interfaceManagementTemplateMapper.selectIsFirstUpload(user_id);
//		System.out.println(map);
		return map;
	}

	@Override
	public void insertInterfaceManagementTemplateUrl(Map<String, Object> map) {
		InterfaceManagementTemplate interfaceManagementTemplate = new InterfaceManagementTemplate();
		String activity_url = map.get("activity_url").toString();
		String invitation_url = map.get("invitation_url").toString();
		interfaceManagementTemplate.setActivity_url(activity_url);
		interfaceManagementTemplate.setInvitation_url(invitation_url);
		interfaceManagementTemplate.setGroup_id(UserContext.getCurrentUserId());
		interfaceManagementTemplate.setCreate_time(new Date());
		interfaceManagementTemplate.setUpdate_time(interfaceManagementTemplate.getCreate_time());
		InterfaceManagementTemplate interfaceManagement = interfaceManagementTemplateMapper.selectOneByGroupId(UserContext.getCurrentUserId());
		if(interfaceManagement != null){
			interfaceManagementTemplate.setId(interfaceManagement.getId());
			interfaceManagementTemplate.setUpdate_time(new Date());
			interfaceManagementTemplateMapper.updateByPrimaryKeySelective(interfaceManagementTemplate);
		}else{
			interfaceManagementTemplateMapper.insertSelective(interfaceManagementTemplate);
		}
	}

}
